import axios from 'axios';

const http = axios.create({
    baseURL: 'http://localhost:8080',
    timeout: 10000
});

http.interceptors.request.use(
    function (config) {
        // 在发送请求之前
        if(config.method === 'post'){
            config.headers['Content-Type'] = 'application/x-www-form-urlencoded'
        }
        return config;
    },
    function (error) {
        // 请求错误
        return Promise.reject(error);
    }
);

http.interceptors.response.use(
    function (response) {
        // 成功响应
        return response;
    },
    function (error) {
        // 响应错误
        return Promise.reject(error);
    }
);

export default http;